//
//  PicCollectionView.swift
//  WeiBo
//
//  Created by wukeng on 16/9/4.
//  Copyright © 2016年 wukeng. All rights reserved.
//

import UIKit

class PicCollectionView: UICollectionView {
    
    var picURLs : [NSURL] = [NSURL](){
        didSet{
            self.reloadData()
        }
    }
    

    override func awakeFromNib() {
        dataSource = self
        delegate = self
    }
}

//数据源
extension PicCollectionView : UICollectionViewDataSource{
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return picURLs.count
    }
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView .dequeueReusableCellWithReuseIdentifier("PicCell", forIndexPath: indexPath) as! picCollectionViewCell
        cell.picURL = picURLs[indexPath.item]
//        cell.backgroundColor = UIColor.blackColor()
        return cell
    }
}

class picCollectionViewCell : UICollectionViewCell {
    var picURL : NSURL? {
        didSet{
            guard let picURL = picURL else{
                return
            }
            iconImage.sd_setImageWithURL(picURL, placeholderImage: UIImage(named: "empty_picture"))
        }
    }
    
    
    @IBOutlet weak var iconImage: UIImageView!
    
}

//代理
extension PicCollectionView : UICollectionViewDelegate{
    
    
}